package com.yu.footballpromotionliveadmin.service.impl;

import com.yu.footballpromotionliveadmin.dao.LiveBroadcasAdministratorDao;
import com.yu.footballpromotionliveadmin.dto.DTO;
import com.yu.footballpromotionliveadmin.dto.MessageEnum;
import com.yu.footballpromotionliveadmin.page.PageInfo;
import com.yu.footballpromotionliveadmin.pojo.LiveBroadcasAdministrator;
import com.yu.footballpromotionliveadmin.service.LiveBroadcasAdministratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class LiveBroadcasAdministratorServiceImpl implements LiveBroadcasAdministratorService {

    @Autowired
    LiveBroadcasAdministratorDao liveBroadcasAdministratorDao;


    @Override
    public DTO<LiveBroadcasAdministrator> getAllLiveBroadcasAdministrators() throws Exception {
        List<LiveBroadcasAdministrator> activityTypes = liveBroadcasAdministratorDao.getAllLiveBroadcasAdministrators();
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum = Optional.ofNullable(activityTypes).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;

        return new DTO<LiveBroadcasAdministrator>(messageEnum.getCode(),messageEnum.getMessage(),activityTypes);
    }

    @Override
    public DTO<LiveBroadcasAdministrator> getLiveBroadcasAdministratorById(String erno) throws Exception {

        LiveBroadcasAdministrator activityType = liveBroadcasAdministratorDao.getLiveBroadcasAdministratorByUno(erno);

        MessageEnum messageEnum = Optional.ofNullable(activityType).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;
        return new DTO<LiveBroadcasAdministrator>(messageEnum.getCode(),messageEnum.getMessage(),activityType);
    }

    @Override
    public DTO<LiveBroadcasAdministrator> deleteLiveBroadcasAdministrator(String erno) throws Exception {
        Integer integer = liveBroadcasAdministratorDao.deleteLiveBroadcasAdministrator(erno);
        MessageEnum messageEnum = integer > 0 ? MessageEnum.DELETEADMINSUCCESS : MessageEnum.DELETEADMINFAIL;
        return new DTO<LiveBroadcasAdministrator>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<LiveBroadcasAdministrator> updateLiveBroadcasAdministrator(LiveBroadcasAdministrator liveBroadcasAdministrator) throws Exception {
        Integer integer = liveBroadcasAdministratorDao.updateLiveBroadcasAdministrator(liveBroadcasAdministrator);

        MessageEnum messageEnum = integer > 0 ? MessageEnum.UPDATEADMINSUCCESS : MessageEnum.UPDATEADMINFAIL;
        return new DTO<LiveBroadcasAdministrator>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<LiveBroadcasAdministrator> addLiveBroadcasAdministrator(LiveBroadcasAdministrator liveBroadcasAdministrator) throws Exception {
        Integer integer = liveBroadcasAdministratorDao.addLiveBroadcasAdministratorByUno(liveBroadcasAdministrator);
        MessageEnum messageEnum = integer > 0 ? MessageEnum.ADDADMINSUCCESS : MessageEnum.ADDADMINFAIL;
        return new DTO<LiveBroadcasAdministrator>(messageEnum.getCode(),messageEnum.getMessage(),liveBroadcasAdministrator);
    }

    @Override
    public DTO<LiveBroadcasAdministrator> getLiveBroadcasAdministratorsByPage(PageInfo pageInfo) throws Exception {
        List<LiveBroadcasAdministrator> activityTypesByPage = liveBroadcasAdministratorDao.getLiveBroadcasAdministratorsByPage(pageInfo);
        MessageEnum messageEnum = Optional.ofNullable(activityTypesByPage).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;

        return new DTO<LiveBroadcasAdministrator>(messageEnum.getCode(),messageEnum.getMessage(),activityTypesByPage);
    }

    @Override
    public DTO<LiveBroadcasAdministrator> getLiveBroadcasAdministratorsWithOrders(String erno) throws Exception {
        return null;
    }

    @Override
    public DTO<LiveBroadcasAdministrator> activate(String erno) throws Exception {
        return null;
    }

    @Override
    public DTO<LiveBroadcasAdministrator> lettory(String erno, String giftName) throws Exception {
        return null;
    }
}
